package com.technology.education.widget

import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.technology.education.data.model.Carousel
import com.technology.education.ext.loadImage
import com.youth.banner.adapter.BannerAdapter

/**
 *@author:create by BZY
 *Date: 2020/5/22 14
 */
class HomeBannerAdapter(datas: ArrayList<Carousel>) :
    BannerAdapter<Carousel, HomeBannerAdapter.BannerViewHolder>(datas) {

    class BannerViewHolder(view: ImageView) :
        RecyclerView.ViewHolder(view) {
        var imageView: ImageView? = null

        init {
            imageView = view
        }
    }

    override fun onCreateHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {
        val imageView = ImageView(parent.context)
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        imageView.scaleType = ImageView.ScaleType.FIT_XY
        return BannerViewHolder(imageView)
    }

    override fun onBindView(
        holder: BannerViewHolder,
        data: Carousel,
        position: Int,
        size: Int
    ) {
        loadImage(data.image, holder.imageView!!)
    }
}